//
//  NetTools.m
//  timelyRain
//
//  Created by Jiafei Wei on 2016/12/26.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "NetTools.h"
#import "AFNetWorking.h"
@implementation NetTools

static NetTools *instance;
+(NetTools *)share{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[NetTools alloc]init];
        [instance getInternetStaus];
    });
    return instance;
}
- (id)init
{
    self = [super init];
    if (self) {
        //[self getInternetStaus];
    }
    return self;
}
//wifi获取的很慢啊
-(void)getInternetStaus{
     __weak typeof(self) weakSelf = self;
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
                NSLog(@"未知网络");
                weakSelf.isHaveInternet=true;
                weakSelf.isWifi=false;
                break;
            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
                weakSelf.isHaveInternet=false;
                weakSelf.isWifi=false;
                break;
                
            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                NSLog(@"手机自带网络");
                weakSelf.isHaveInternet=true;
                weakSelf.isWifi=false;
                break;
                
            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                NSLog(@"WIFI");
                weakSelf.isHaveInternet=true;
                weakSelf.isWifi=true;
                break;
        }
    }];
    [mgr startMonitoring];
}
@end
